/* Gluten Library -- Camera
 *
 * A simple, first-person perspective camera.
 *
 * $AUTHOR$    res
 * $UPDATE$    r19
 */

/* LICENSES ********************************************************************

   Copyright (c) 2013- Reuben E. Smith

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files (the "Software"), to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.

 *******************************************************************************/


#ifndef GLUTEN_CAMERA_HPP
#define GLUTEN_CAMERA_HPP

#include "Vector.hpp"


namespace Gluten
{
   //! \class Camera
   //! \brief First-person view matrix controller.
   class Camera
   {
   public:
      //! \brief Default constructor. Position and rotation are zeroed.
      Camera();

      //! \brief Copy constructor.
      //! \param[in]    other          camera to copy
      Camera(const Camera& other);

      //! \brief Parametric constructor. Initializes camera values.
      //! \param[in]    pos            camera position
      //! \param[in]    rot            camera rotation
      Camera(const Vector4f& pos, const Vector4f& rot);

      //! \brief Parametric constructor. Initializes camera values.
      //! \param[in]    px             camera x-coordinate
      //! \param[in]    py             camera y-coordinate
      //! \param[in]    pz             camera z-coordinate
      //! \param[in]    rx             camera pitch
      //! \param[in]    ry             camera yaw
      //! \param[in]    rz             camera roll
      Camera(float px, float py, float pz, float rx, float ry, float rz);

      //! \brief Assignment operator. Copies another camera's matrix.
      //! \param[in]    other          camera to copy
      //! \return       this camera
      Camera& operator=(const Camera& other);

      //! \brief Test if two cameras are equivalent.
      //! \param[in]    other          camera to test
      //! \return       true if equal or not equal, respectively
      bool operator==(const Camera& other) const;
      bool operator!=(const Camera& other) const;

      //! \brief Apply the camera view matrix to the scene. Must be called
      //! \brief after all camera transformations.
      void view();

      //! \brief Reset camera rotation and position.
      void reset();

      //! \brief Reset camera position.
      void resetPosition();

      //! \brief Reset camera rotation.
      void resetRotation();

      //! \brief Get the camera forward vector.
      //! \return       forward vector of camera
      Vector4f getForwardV() const;

      //! \brief Set camera forward vector.
      //! \param[in]    v              new forward vector
      void setForwardV(const Vector4f& v);

      //! \brief Get the camera right vector.
      //! \return       right vector of camera
      Vector4f getRightV() const;

      //! \brief Set camera right vector.
      //! \param[in]    v              new right vector
      void setRightV(const Vector4f& v);

      //! \brief Get the camera up vector.
      //! \return       up vector of camera
      Vector4f getUpV() const;

      //! \brief Set camera up vector.
      //! \param[in]    v              new up vector
      void setUpV(const Vector4f& v);

      //! \brief Get the camera global position.
      //! \return       the camera's position
      Vector4f getPosition() const;

      //! \brief Set the camera global position.
      //! \param[in]    pt             the camera's new position
      void setPosition(const Vector4f& pt);

      //! \brief Set the camera global position.
      //! \param[in]    x              new x-coordinate
      //! \param[in]    y              new y-coordinate
      //! \param[in]    z              new z-coordinate
      void setPosition(float x, float y, float z);

      //! \brief Move camera globally.
      //! \param[in]    d              how far camera should move
      //! \param[in]    axes           x-, y-, and z-axis values to use
      //!
      //! Global camera movement will absolutely position the camera in the
      //! scene. This means that movG(1, vec(0, 1, 0)) will move the camera up
      //! one unit regardless of how the camera is rotated.
      void movG(float d, const Vector4f& axes);

      //! \brief Move camera globally.
      //! \param[in]    d              how far camera should move
      //! \param[in]    axisX          x-axis value to use
      //! \param[in]    axisY          y-axis value to use
      //! \param[in]    axisZ          z-axis value to use
      //!
      //! Global camera movement will absolutely position the camera in the
      //! scene. This means that movG(1, 0, 1, 0) will move the camera up
      //! one unit regardless of how the camera is rotated.
      void movG(float d, float axisX, float axisY, float axisZ);

      //! \brief Move camera locally.
      //! \param[in]    d              how far camera should move
      //! \param[in]    axes           x-, y-, and z-axis values to use
      //!
      //! Local camera movement will position the camera based on the current
      //! orientation. This means that movL(1, vec(0, 0, 1)) will move the 
      //! camera one unit forward in whatever direction the camera is facing.
      void movL(float d, const Vector4f& axes);

      //! \brief Move camera locally.
      //! \param[in]    d              how far camera should move
      //! \param[in]    axisX          x-axis value to use
      //! \param[in]    axisY          y-axis value to use
      //! \param[in]    axisZ          z-axis value to use
      //!
      //! Local camera movement will position the camera based on the current
      //! orientation. This means that movL(1, 0, 0, 1) will move the camera
      //! one unit forward in whatever direction the camera is facing.
      void movL(float d, float axisX, float axisY, float axisZ);

      //! \brief Rotate camera globally.
      //! \param[in]    d              how many degrees camera should rotate
      //! \param[in]    axes           x-, y-, and z-axis values to use
      //!
      //! Global camera rotation will rotate the camera irrespective of any
      //! current rotation. This means that rotG(45, vec(0, 1, 0)) will yaw
      //! the camera 45 degrees right about the global y-axis -- what most
      //! first-person cameras do.
      void rotG(float d, const Vector4f& axes);

      //! \brief Rotate camera globally.
      //! \param[in]    d              how many degrees camera should rotate
      //! \param[in]    axisX          x-axis value to use
      //! \param[in]    axisY          y-axis value to use
      //! \param[in]    axisZ          z-axis value to use
      //!
      //! Global camera rotation will rotate the camera irrespective of any
      //! current rotation. This means that rotG(45, 0, 1, 0) will yaw
      //! the camera 45 degrees right about the global y-axis -- what most
      //! first-person cameras do.
      void rotG(float d, float axisX, float axisY, float axisZ);

      //! \brief Rotate camera locally.
      //! \param[in]    d              how many degrees camera should rotate
      //! \param[in]    axes           x-, y-, and z-axis values to use
      //!
      //! Local camera rotation will rotate the camera using the current
      //! rotated coordinate system. This is how a flying object would rotate.
      void rotL(float d, const Vector4f& axes);

      //! \brief Rotate camera locally.
      //! \param[in]    d              how many degrees camera should rotate
      //! \param[in]    axisX          x-axis value to use
      //! \param[in]    axisY          y-axis value to use
      //! \param[in]    axisZ          z-axis value to use
      //!
      //! Local camera rotation will rotate the camera using the current
      //! rotated coordinate system. This is how a flying object would rotate.
      void rotL(float d, float axisX, float axisY, float axisZ);


   private:
      float _m[16];
      float* _p;
      float* _f;
      float* _r;
      float* _u;
   };
}

#endif

